package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysBlacklist;
import com.ruoyi.project.system.service.ISysBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/system/blacklist")
public class SysBlacklistController extends BaseController
{
    @Autowired
    private ISysBlacklistService sysBlacklistService;

    /**
     * 查询行业黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('system:blacklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBlacklist sysBlacklist)
    {
        startPage();
        List<SysBlacklist> list = sysBlacklistService.selectSysBlacklistList(sysBlacklist);
        return getDataTable(list);
    }

    /**
     * 导出行业黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('system:blacklist:export')")
    @Log(title = "行业黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBlacklist sysBlacklist)
    {
        List<SysBlacklist> list = sysBlacklistService.selectSysBlacklistList(sysBlacklist);
        ExcelUtil<SysBlacklist> util = new ExcelUtil<SysBlacklist>(SysBlacklist.class);
        util.exportExcel(response, list, "行业黑名单数据");
    }

    /**
     * 获取行业黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:blacklist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysBlacklistService.selectSysBlacklistById(id));
    }

    /**
     * 新增行业黑名单
     */
    @PreAuthorize("@ss.hasPermi('system:blacklist:add')")
    @Log(title = "行业黑名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBlacklist sysBlacklist)
    {
        return toAjax(sysBlacklistService.insertSysBlacklist(sysBlacklist));
    }

    /**
     * 修改行业黑名单
     */
    @PreAuthorize("@ss.hasPermi('system:blacklist:edit')")
    @Log(title = "行业黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBlacklist sysBlacklist)
    {
        return toAjax(sysBlacklistService.updateSysBlacklist(sysBlacklist));
    }

    /**
     * 删除行业黑名单
     */
    @PreAuthorize("@ss.hasPermi('system:blacklist:remove')")
    @Log(title = "行业黑名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysBlacklistService.deleteSysBlacklistByIds(ids));
    }
}
